package api

import (
	"crypto/md5"
	"fmt"
	"github.com/lishimeng/app-starter"
	"io"
	"strconv"
	"time"
)

type FileResponse struct {
	File    string `json:"filePath"`
	Name    string `json:"fileName"`
	Success bool   `json:"success"`
}

type UploadResponse struct {
	app.Response
	FileResponse
}

type MultipleUploadResponse struct {
	app.Response
	Success int            `json:"success"`
	Fail    int            `json:"fail"`
	Items   []FileResponse `json:"items"`
}

func genTmpFileName(name string) (res string) {
	now := time.Now().Unix()
	h := md5.New()
	_, _ = io.WriteString(h, name+strconv.FormatInt(now, 10))
	res = fmt.Sprintf("%x", h.Sum(nil))
	return
}
